package com.jason.core.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2018/5/11.
 */
public class UUIDUtil {

    public static String getRandomUUID( String prefix, Date date, int code ) {
        //1、创建时间戳
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String dateNowStr = prefix + dateFormat.format(date);
        StringBuffer one = new StringBuffer(dateNowStr);
        one.append("-");
        if (code / 10 == 0) {
            one.append("000");
            one.append(code);
        } else if (code / 100 == 0) {
            one.append("00");
            one.append(code);
        } else if (code / 1000 == 0) {
            one.append("0");
            one.append(code);
        } else if (code / 10000 == 0) {
            one.append(code);
        }
        System.out.println(one.toString());
      /*  //2、创建随机对象
        Random rd = new Random();

        //3、产生4位随机数
        String n = "";
        int rdGet; //取得随机数

        do {
            rdGet = Math.abs(rd.nextInt()) % 10 + 48; //产生48到57的随机数(0-9的键位值)
            // rdGet=Math.abs(rd.nextInt())%26+97; //产生97到122的随机数(a-z的键位值)
            char num1 = (char) rdGet;
            String dd = Character.toString(num1);
            n += dd;
        } while (n.length() < 4);// 假如长度小于4
        sb.append(n);*/

        //4、返回唯一码
        return one.toString();
    }
}
